package com.shujia.wyh.day27.easyfactory;

public class AnimalFactory {

    //将构造方法私有化，让外界无法创建对象
    private AnimalFactory(){

    }

//    public static Dog createDog(){
//        return new Dog();
//    }
//    public static Cat createCat(){
//        return new Cat();
//    }

    //利用多态来创建对象
    public static Animal createAnimal(String name){
        if("dog".equals(name)){
            return new Dog();
        }else if("cat".equals(name)){
            return new Cat();
        }else {
            System.out.println("动物工厂暂时不支持创建"+name+"动物");
            return null;
        }
    }
}
